package com.tuling.dal.service.impl;

import com.tuling.dal.entity.PmsProductFullReduction;
import com.tuling.dal.dao.PmsProductFullReductionDao;
import com.tuling.dal.service.PmsProductFullReductionService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 产品满减表(只针对同商品)(PmsProductFullReduction)表服务实现类
 *
 * @author makejava
 * @since 2025-05-01 18:23:21
 */
@Service
public class PmsProductFullReductionServiceImpl implements PmsProductFullReductionService {
    @Resource
    private PmsProductFullReductionDao pmsProductFullReductionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PmsProductFullReduction queryById(Long id) {
        return this.pmsProductFullReductionDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pmsProductFullReduction 筛选条件
     * @param pageRequest             分页对象
     * @return 查询结果
     */
    @Override
    public Page<PmsProductFullReduction> queryByPage(PmsProductFullReduction pmsProductFullReduction, PageRequest pageRequest) {
        long total = this.pmsProductFullReductionDao.count(pmsProductFullReduction);
        return new PageImpl<>(this.pmsProductFullReductionDao.queryAllByLimit(pmsProductFullReduction, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pmsProductFullReduction 实例对象
     * @return 实例对象
     */
    @Override
    public PmsProductFullReduction insert(PmsProductFullReduction pmsProductFullReduction) {
        this.pmsProductFullReductionDao.insert(pmsProductFullReduction);
        return pmsProductFullReduction;
    }

    /**
     * 修改数据
     *
     * @param pmsProductFullReduction 实例对象
     * @return 实例对象
     */
    @Override
    public PmsProductFullReduction update(PmsProductFullReduction pmsProductFullReduction) {
        this.pmsProductFullReductionDao.update(pmsProductFullReduction);
        return this.queryById(pmsProductFullReduction.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.pmsProductFullReductionDao.deleteById(id) > 0;
    }
}
